package com.forcht.ioc.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * Created by forcht on 2018/4/20.
 */
public class TimerInterceptor implements MethodInterceptor{
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        long time=System.nanoTime();
        System.out.println("Invocation of method "+methodInvocation.getMethod().getName()+"start");
        Object proceed = methodInvocation.proceed();
        System.out.println("Invocation of method "+methodInvocation.getMethod().getName()+"end! takes "+(System.nanoTime()-time));
        return proceed;
    }
}
